package com.lb.shopguide.ui.dialog;

import android.content.Context;
import android.content.DialogInterface;
import android.support.design.widget.TextInputLayout;
import android.support.v7.app.AlertDialog;
import android.view.View;

import com.lb.shopguide.R;

/**
 * Created by kang on 2018/1/24.
 */

public class DialogCommonEdittext {

    private Context mContext;

    public DialogCommonEdittext(Context context) {
        this.mContext = context;
    }

    public AlertDialog getAlertDialog(View view, String hint) {
        TextInputLayout layout = view.findViewById(R.id.text_input_layout);
        layout.setHint(hint);
        final AlertDialog dialog = new AlertDialog.Builder(mContext).setTitle(" ")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
//                        mPresenter.deleteTopic(bbsId, topicId);
                        if (mListener != null) {
                            mListener.onSure(dialog, which);
                        }
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (mListener != null) {
                            mListener.onCancel(dialog, which);
                        }
                    }
                }).setView(view)
                .create();
        dialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface arg0) {
                dialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(mContext.getResources().getColor(R.color.sg_common_red));
                dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(mContext.getResources().getColor(R.color.sg_black));
            }
        });
        return dialog;
    }

    public interface OnDialogClickListener {
        void onSure(DialogInterface dialog, int which);

        void onCancel(DialogInterface dialog, int which);
    }

    private DialogMakeSure.OnDialogClickListener mListener;

    public void setOnDialogClickListener(DialogMakeSure.OnDialogClickListener listener) {
        this.mListener = listener;
    }
}
